export default{
	common:{
		baseUrl:"http://localhost:6699/yunduo",
		data:{},
		header:{
			"Content-Type":"application/json",
		},
		method:"GET",
		dataType:"json"
	},
	setToken(token){
		this.common.header={
			"Content-Type":"application/json",
			"Authorization":token
		}
	},
	request(options={}){
		options.url = this.common.baseUrl + options.url;
		options.data = options.data || this.common.data;
		options.header =  this.common.header;
		options.method = options.method || this.common.method;
		options.dataType = options.dataType || this.common.dataType;
		return new Promise((res,rej)=>{
			uni.request({
				...options,
				success:(result)=>{
					if(parseInt(result.data.code) != 200){
						uni.showToast({
							title:result.message,
							icon:'error',
							duration:2000
						})
						rej('请求失败');
					}
					let data = result.data;
					res(data)
				}
			})
		})
	}
}